package com.fz.consumer.listeners;

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class MqListener {
    @RabbitListener(queues = "simple.queue")
    public void listenSimpleQueue(String msg){
        log.info("接收到消息：{}",msg);
    }

    @RabbitListener(queues = "work.queue")
    public void listWorkQueue1(String msg){
        log.info("消费者1 收到了 work.queue的消息： 【{}】",msg);
        try {
            // 模拟服务器处理业务需要20毫秒
            Thread.sleep(20);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
    }

    @RabbitListener(queues = "work.queue")
    public void listWorkQueue2(String msg){
        log.info("消费者2 收到了 work.queue的消息............： 【{}】",msg);
        try {
            // 模拟服务器处理业务需要200毫秒
            Thread.sleep(200);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
    }

    @RabbitListener(queues = "fanout.queue1")
    public void listFanoutQueue1(String msg){
        log.info("消费者1 收到了 fanout.queue1的消息。。。。【{}】",msg);
    }

    @RabbitListener(queues = "fanout.queue2")
    public void listFanoutQueue2(String msg){
        log.info("消费者2 收到了 fanout.queue2的消息。。。。【{}】",msg);
    }

    @RabbitListener(queues = "direct.queue1")
    public void listDirectQueue1(String msg){
        log.info("消费者1 收到了 direct.queue1的消息。。。。【{}】",msg);
    }

    @RabbitListener(queues = "direct.queue2")
    public void listDirectQueue2(String msg){
        log.info("消费者2 收到了 direct.queue2的消息。。。。【{}】",msg);
    }

    @RabbitListener(queues = "topic.queue1")
    public void listTopicQueue1(String msg){
        log.info("消费者1 收到了 topic.queue1的消息。。。。【{}】",msg);
    }

    @RabbitListener(queues = "topic.queue2")
    public void listTopicQueue2(String msg){
        log.info("消费者2 收到了 topic.queue2的消息。。。。【{}】",msg);
    }
}
